package com.societyGames.precedenceExercises
{
	import com.societyGames.action.ActionQueue;
	import com.societyGames.action.CallbackAction;
	import com.societyGames.action.DelayAction;
	import com.societyGames.system.EventObject;
	
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextLineMetrics;

	public class PrecedenceRender extends Sprite
	{	
		private var _precedenceSimulation:PrecedenceSimulation;
		private var _actionQueue:ActionQueue;
		
		private var _expressionTextField:TextField;
		private var _scratchTextField:TextField;
		
		public function PrecedenceRender(precedenceSimulation:PrecedenceSimulation, actionQueue:ActionQueue)
		{	
			this._precedenceSimulation = precedenceSimulation;
			this._actionQueue = actionQueue;
			
			this._expressionTextField = new TextField();
			this._expressionTextField.border = true;
			this._expressionTextField.borderColor = 0;
			this.addChild(this._expressionTextField);
			
			this._scratchTextField = new TextField();
			this.addChild(this._scratchTextField);
		}
		
		public function setExpression(expression:INumberExpression, x:Number, y:Number, z:Number):void
		{
			this._expressionTextField.text = "output(" + Object(expression).toString() + ");";
			var metrics:TextLineMetrics = this._expressionTextField.getLineMetrics(0);
			this._expressionTextField.width = metrics.width + 4;
			this._expressionTextField.height = metrics.height + 4;
			
			this._scratchTextField.y = this._expressionTextField.y + this._expressionTextField.height;
			this._scratchTextField.text = "";
			this._scratchTextField.mouseEnabled = false;
			this._scratchTextField.appendText("\nX = " + x);
			this._scratchTextField.appendText("\nY = " + y);
			this._scratchTextField.appendText("\nZ = " + z);
			this._scratchTextField.appendText("\noutput = " + expression.evaluate());
		}
	}
}